home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / varia / interp18.lha / interp-1.8 / Context.cc < prev    next >
C/C++ Source or Header  |  1990-01-20  |  3KB  |  91 lines

  1. // Context.cc -- the definition of the member functions for class Context.
  2. // Copyright (C) 1989 Carey Richard Murphey.
  3. // (rich@rice.edu) 5310 Rutherglenn, Houston, TX 77096
  4.  
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 1, or (at your option)
  8. // any later version.
  9.  
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14.  
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. #include "Context.h"
  20.  
  21. #if !defined(__OPTIMIZE__) || defined(INLINE)
  22. #ifndef INLINE
  23. #define INLINE
  24. #endif
  25.  
  26. INLINE void Context:: open ()    // create a new symbol table at the
  27.                 // opening of a block.
  28. {
  29.   tab.add_high (new StringSymbolpAVLMap (new Double_Pointer(0.)));
  30. }
  31.  
  32. INLINE void Context:: close ()        // close a context
  33. {
  34.   if (tab.high_element ()->length () == 0)
  35.     delete tab.high_element ();
  36.   tab.del_high ();
  37. };
  38.  
  39. INLINE int Context:: contains (String& name)
  40. {
  41.   // Look through the symbol tables for a given name.
  42.   // Return 1 if found or 0 if not found.
  43.  
  44.   for (int i = tab.high(); i > tab.ecnef(); tab.prev(i))
  45.     {
  46.       if (tab[i]->contains(name))
  47.     return 1;
  48.     }
  49.   return 0;
  50. }
  51.  
  52. INLINE int Context:: top_level (String& name)
  53. {
  54.   // Look through the top level (outermost) symbol tables for a given name.
  55.   // Return 1 if found or 0 if not found.
  56.  
  57.   if (tab.high_element ()->contains(name))
  58.     return 1;
  59.   return 0;
  60. }
  61.  
  62. INLINE Symbol& Context:: operator [] (String& name)
  63. {
  64.   // Look through the symbol tables for a given name.
  65.   // If not found, put it in the outermost table.
  66.   // Return a reference to that symbol.
  67.  
  68.   for (int i = tab.high(); i > tab.ecnef(); tab.prev(i))
  69.     {
  70.       if (tab[i]->contains(name))
  71.     return *(*tab[i])[name];
  72.     }
  73.   return *(*tab.high_element ())[name];
  74. }
  75.  
  76. INLINE Table Context:: table (String& name)
  77. {
  78.   // Look through the symbol tables for a given name.
  79.   // If not found, return a pointer to the outermost table without installing.
  80.   // Return a pointer to table .
  81.  
  82.   for (int i = tab.high(); i > tab.ecnef(); tab.prev(i))
  83.     {
  84.       if (tab[i]->contains(name))
  85.     return tab[i];
  86.     }
  87.   return tab.high_element ();
  88. }
  89.  
  90. #endif
  91.